package com.icore.bean;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import org.json.JSONException;
import org.json.JSONObject;

import com.icore.AppException;

/**
 * 结果类
 * 
 */
public class RetRes extends BaseEntity {
	public static RetRes parse(InputStream stream) throws AppException {
		RetRes retRes = new RetRes();

		try {
			String res = readByByte(stream, -1, new ByteArrayOutputStream(1024));
			if (res != null && res.length() > 0) {
				try {
					JSONObject resObj = new JSONObject(res);
					int code = resObj.getInt("code");
					retRes.setResCode(code);
					retRes.setResMessage(resObj.getString("description"));
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
		} catch (AppException e) {
			e.printStackTrace();
			throw AppException.io(e);
		}
		return retRes;
	}
}
